package com.guigu.servicegoods.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicegoods.domain.TbAlbum;
import com.guigu.servicegoods.service.TbAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicegoods/album")
public class TbAlbumController {

    @Autowired
    private TbAlbumService albumService;

    // 分页条件查询
    @PostMapping("/findPage")
    public Result findPage(@RequestBody(required = false) Map<String, Object> searchMap, Integer page, Integer size) {
        return albumService.findPage(searchMap, page, size);
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody TbAlbum album) {
        boolean save = albumService.save(album);
        if (save){
            return Result.ok();
        }
        return Result.error();
    }

    @PostMapping("/update")
    public Result update(@RequestBody TbAlbum album) {
        boolean update = albumService.updateById(album);
        if (update) {
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        boolean remove = albumService.removeById(id);
        if (remove){
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("/findById")
    public Result findById(Integer id) {
        TbAlbum album = albumService.getById(id);
        if (album==null){
            return Result.error();
        }
        return Result.ok().data("album",album);
    }

}

